package interfazGrafica;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

import processing.core.PApplet;
import processing.core.PVector;

public class ParticleSystem implements Serializable{

	private static final long serialVersionUID = 1L;

	private ArrayList<Particle> particles;
	private PVector origin;
	private PApplet parent;

	public ParticleSystem(PVector location, PApplet p) {
		parent=p;
		origin = location.get();
		particles = new ArrayList<Particle>();
	}

	public void addParticle() {
		particles.add(new Particle(origin,parent));
	}

	public void run() {
		Iterator<Particle> it = particles.iterator();
		while (it.hasNext()) {
			Particle p = it.next();
			p.run();
			if (p.isDead()) {
				it.remove(); 
			}
		}
	}
}